1 <?php
2 session_start();
3 include("header.php");
4 include("sidebar.php");
5 include("dbconnection.php");
6 ?>
7
8 <script type="text/javascript">
9 function validate()
10 {
11 if(document.form1.vehname.value=="")
12 {
13 alert("Enter Vehicle");
14 document.form1.vehname.focus();
15 return false;
16 }
17 if(document.form1.model.value=="")
18 {
19 alert("Enter Model");
20 document.form1.model.focus();
21 return false;
22 }
23 if(document.form1.brand.value=="")
24 {
25 alert("Enter Brand");
26 document.form1.brand.focus();
27 return false;
28 }
29 if(document.form1.estdprice.value=="")
30 {
31 alert("Enter the Estimated Price");
32 document.form1.estdprice.focus();
33 return false;
34 }
35 if(document.form1.other.value=="")
36 {
37 alert("Enter other info");
38 document.form1.other.focus();
39 return false;
40 }
41
42 }
43 </script>
44 <?php
45 if(isset($_POST["submit"]))
46 {
47
48 move_uploaded_file($_FILES["file"]["tmp_name"],
49 "upload/" . $_FILES["file"]["name"]);
50 $img = $_FILES["file"]["name"];
51 $sql ="insert into vehicle(custid,vehname,model,brand,images,estmdprice,otherinfo,status) values('$_SESSION[custid]','$_POST[vehname]','$_POST[model]','$_POST[brand]','$img','$_POST[estdprice]','$_POST[other]','Pending')";
52
53 if (!mysql_query($sql,$con))
54 {
55 die('Error: ' . mysql_error());
56 }
57 }
58
59 if(isset($_POST["update"]))
60 {
61
62 move_uploaded_file($_FILES["file"]["tmp_name"],
63 "upload/" . $_FILES["file"]["name"]);
64 $img = $_FILES["file"]["name"];
65 if(empty($img)){
66 $img = $_POST['image'];
67 }
68
69 if($img != "")
70 {
71 $sql ="update vehicle set custid='$_SESSION[custid]',vehname='$_POST[vehname]',model='$_POST[model]',brand='$_POST[brand]',images='$img',estmdprice='$_POST[estdprice]',otherinfo='$_POST[other]' where sellno='$_GET[updtid]'";
72 }
73 else
74 {
75 $sql ="update vehicle set custid='$_SESSION[custid]',vehname='$_POST[vehname]',model='$_POST[model]',brand='$_POST[brand]',estmdprice='$_POST[estdprice]',otherinfo='$_POST[other]' where sellno='$_GET[updtid]'";
76 }
77 if (!mysql_query($sql,$con))
78 {
79 die('Error: ' . mysql_error());
80 }
81
82 if(mysql_affected_rows() == 1)
83 {
84 $recresult = "<font color='green'><b>Vehicle record updated successfully...</b></font>";
85 }
86 }
87 ?>
88 <?php
89
90 if(isset($_GET['updtid']))
91 {
92 $sql = mysql_query("select * from vehicle where sellno='$_GET[updtid]'");
93 $row = mysql_fetch_array($sql);
94 }
95 ?>
96
97 <div id="main">
98
99 <a name="TemplateInfo"></a>
100 <h1>Sell vehicles</h1>
101 <?php
102 if(isset($_POST[submit]))
103 {
104 ?>
105 <center><h3>Vehicles record added successfully.. </center></h3>
106 <?php
107 }
108 else
109 {
110 echo $recresult;
111 ?>
112
113 <form action="" method="post" enctype="multipart/form-data" onsubmit="return validate()" name="form1" id="form1">
114 <table width="484" border="0">
115 <tr>
116 <th width="264" height="37" scope="row">Vehicle Name
117 <label for="lname"></label></th>
118 <td width="210"><label for="vehname"></label>
119 <input name="vehname" type="text" value="<?php echo $row['vehname']; ?>" id="vehname" size="35" /></td>
120 </tr>
121 <tr>
122 <th height="36" scope="row">Model</th>
123 <td><label for="email"></label>
124 <label for="model"></label>
125 <input name="model" type="text" value="<?php echo $row['model']; ?>" id="model" size="35" /></td>
126 </tr>
127 <tr>
128 <th height="47" scope="row">Brand</th>
129 <td><label for="password"></label>
130 <input name="brand" type="text" value="<?php echo $row['brand']; ?>" id="brand" size="35" /></td>
131 </tr>
132 <tr>
133 <th height="40" scope="row" valign="top"><br />
134 Images</th>
135 <td><label for="confpass"></label>
136 <label for="images"></label>
137 <label for="file"></label>
138 <input type="file" name="file" id="file" /><input type="hidden" name="image" />
139 <?php if(isset($_GET['updtid']))
140 {
141 ?>
142 <?php
143 if($row['images'] == "")
144 {
145 $imgsrc = "images/noimage.png";
146 }
147 else
148 {
149 $imgsrc = "upload/$row[images]";
150 }
151 ?>
152
153 <img src="<?php echo $imgsrc; ?>" width="179" height="148" />
154 <?php
155 }
156 ?>
157 </td>
158 </tr>
159 <tr>
160 <th height="37" scope="row">Estimated Price (In $)</th>
161 <td><label for="phone"></label>
162 <label for="estdprice"></label>
163 <input name="estdprice" type="text" value="<?php echo $row['estmdprice']; ?>" id="estdprice" size="35" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/></td>
164 </tr>
165 <tr>
166 <th height="45" scope="row">Other Info</th>
167 <td><label for="mobile"></label>
168 <label for="other"></label>
169 <textarea name="other" cols="15" id="other" ><?php echo $row['otherinfo']; ?></textarea></td>
170 </tr>
171 <tr>
172 <th scope="row"> </th>
173 <td>
174 <?php if(isset($_GET['updtid']))
175 {
176 ?>
177 <input type="submit" name="update" id="update" value="Update vehicle" /><?php }else{ ?><input type="submit" name="submit" id="submit" value="Sell vehicle" /><?php } ?></td>
178 </tr>
179 </table>
180 <?php
181 }
182 ?>
183 </form>
184 <p> </p>
185 <br />
186
187 </div>
188
189 <!-- wrap ends here -->
190 </div>
191
192 <?php
193 include("footer.php");
194 ?>